<uieip type="page" value="base"></uieip>
<uieip type="reg" value="console,cms"></uieip>
<uieip type="tmpl" value="cms.title"></uieip>
<script runat="server">
    var ui_data = request.data("cms.title");

    //var ui_data = request.data("cms.nav");
    //var ui_data = _tmp_cms_nav;
    var linkurl = (ui_data.path + "/" + ui_data.name + ".html").toLowerCase();
    var nav_root = getroot_nav();
    var nav_path = [];
    getpaths([], nav_root);

    if (nav_path.length > 0) {
        var nav = nav_path[nav_path.length - 1];
        cms.title(nav.PTitle == "" ? nav.Name : "", nav.PDescribe, nav.PKeywords);
    } else {
        cms.title("未设置", "远齐,科技", "远齐科技（北京）有限公司...");
    }


    request.dataset("_nav_root", nav_root);
    request.dataset("_linkurl", linkurl);
    request.dataset("_nav_path", nav_path);

    function getroot_nav() {
        for (let i = 0; i < ui_data.navs.length; i++) {
            var nav = ui_data.navs[i];
            if (nav.Path.toLowerCase() == "account/index") {
                return nav;
            }
        }

        return undefined;
    }

    function getpaths(navs, nav) {
        navs.push(nav);
        if ("account/" + nav.ListUrl.toLowerCase() == linkurl) {
            nav_path = navs;
            return;
        }

        if (nav.Subs === undefined || nav.Subs === null) {
            return;
        }

        for (let i = 0; i < nav.Subs.length; i++) {
            getpaths(navs, nav.Subs[i]);
        }
    }
</script>